﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YYS.Sys
{
    /// <summary>
    /// 当前操作用户
    /// </summary>
    public partial class mCurrentUser : Model
    {
        #region 当前操作用户
        /// <summary>
        /// 当前操作学校ID
        /// </summary>
        public int FnSI_ID { get; set; }
        /// <summary>
        /// 当前操作校区ID
        /// </summary>
        public int FnBSI_ID { get; set; }
        /// <summary>
        /// 当前操作校区识别码
        /// </summary>
        public string FsBSI_IDCode { get; set; }
        /// <summary>
        /// 校智付学校ID
        /// </summary>
        public string FsBSI_IDXiaoPay { get; set; }
        /// <summary>
        /// 当前操作校区所属平台 0：互学通；1：安智；
        /// </summary>
        public short FnBSI_PlatformType { get; set; }
        /// <summary>
        /// 当前操作学校简称
        /// </summary>
        public string FsBSI_ShortName { get; set; }
        /// <summary>
        /// 当前操作学校所在服务器IP（基础数据）
        /// </summary>
        public string FsBSI_ServerIP { get; set; }
        /// <summary>
        /// 当前操作学校数据库名称（基础数据）
        /// </summary>
        public string FsBSI_DBName { get; set; }
        /// <summary>
        /// 当前操作学校所在服务器IP（消费）
        /// </summary>
        public string FsBSI_ExpServerIP { get; set; }
        /// <summary>
        /// 当前操作学校数据库名称（消费）
        /// </summary>
        public string FsBSI_ExpDBName { get; set; }
        /// <summary>
        /// 当前操作学校所属公众号ID
        /// </summary>
        public int FnPUB_ID { get; set; }
        /// <summary>
        /// 学校控制项
        /// </summary>
        public string FsBSI_ControlSets { get; set; }
        /// <summary>
        /// 当前操作学校归属地区ID
        /// </summary>
        public int FnAI_ID { get; set; }
        /// <summary>
        /// 当前操作学校归属地区名称
        /// </summary>
        public string FsAI_Description { get; set; }
        /// <summary>
        /// 当前操作用户ID
        /// </summary>
        public int FnUI_CurrentID { get; set; }
        /// <summary>
        /// 当前操作用户识别码
        /// </summary>
        public string FsUI_IDCode { get; set; }
        /// <summary>
        /// 当前操作用户校智付ID
        /// </summary>
        public string FsUI_IDXiaoPay { get; set; }

        short _FnUI_Type = -1;
        /// <summary>
        /// 当前操作用户类型
        /// </summary>
        public short FnUI_Type { get { return _FnUI_Type; } set { _FnUI_Type = value; } }
        /// <summary>
        /// 当前操作用户姓名
        /// </summary>
        public string FsUI_Name { get; set; }
        /// <summary>
        /// 当前操作用户年级ID
        /// </summary>
        public int FnGI_ID { get; set; }
        /// <summary>
        /// 当前操作用户年级识别码
        /// </summary>
        public string FsGI_IDCode { get; set; }
        /// <summary>
        /// 当前操作用户年级名称
        /// </summary>
        public string FsGI_Name { get; set; }
        /// <summary>
        /// 当前操作用户班级ID
        /// </summary>
        public int FnCI_ID { get; set; }
        /// <summary>
        /// 当前操作用户班级识别码
        /// </summary>
        public string FsCI_IDCode { get; set; }
        /// <summary>
        /// 当前操作用户班级名称
        /// </summary>
        public string FsCI_Name { get; set; }
        /// <summary>
        /// 当前操作用户班级类型
        /// </summary>
        public string FnCI_Type { get; set; }
        /// <summary>
        /// 当前操作用户基础ID
        /// </summary>
        public int FnUI_BaseID { get; set; }
        /// <summary>
        /// 当前操作用户内部ID
        /// </summary>
        public int FnUI_UserID { get; set; }
        /// <summary>
        /// 当前操作用户计费用户ID
        /// </summary>
        public int FnUI_FeeID { get; set; }
        /// <summary>
        /// 当前操作用户关联主ID
        /// </summary>
        public int FnUI_MainID { get; set; }

        List<int> _TeacherFnList = new List<int>();
        /// <summary>
        /// 教师权限列表
        /// <para>FnUI_Type = 0 时有效</para>
        /// </summary>
        public List<int> TeacherFnList { get { return _TeacherFnList; } set { _TeacherFnList = value; } }
        /// <summary>
        /// 是否班主任
        /// <para>FnUI_Type = 0 时有效</para>
        /// </summary>
        public bool IsClassMaster { get; set; }
        /// <summary>
        /// 最高职务级别
        /// <para>FnUI_Type = 0 时有效</para>
        /// </summary>
        public int MaxDutyLevel { get; set; }
        /// <summary>
        /// 学校是否安装道闸
        /// </summary>
        public bool SchoolHasDaozha { get; set; }

        /// <summary>
        /// 费用
        /// </summary>
        public class FeeInfo
        {
            public FeeInfo()
            {
                this.pkgList = new List<PkgInfo>();
            }
            /// <summary>
            /// 余额
            /// </summary>
            public decimal balance { get; set; }
            /// <summary>
            /// 套餐类型
            /// </summary>
            public short cmiStyle { get; set; }
            /// <summary>
            /// 功能包列表
            /// </summary>
            public List<PkgInfo> pkgList { get; set; }

            /// <summary>
            /// 功能包
            /// </summary>
            public class PkgInfo
            {
                public PkgInfo()
                {
                    this.svcList = new List<int>();
                }
                /// <summary>
                /// 是否当前套餐
                /// </summary>
                public int isCurrentCMI { get; set; }
                /// <summary>
                /// 功能包ID
                /// </summary>
                public int fcpId { get; set; }
                /// <summary>
                /// 功能包类型
                /// </summary>
                public short fcpStyle { get; set; }
                /// <summary>
                /// 功能包价格
                /// </summary>
                public decimal fcpPrice { get; set; }
                /// <summary>
                /// 是否有费用 0：欠费； 1：正常； 2：暂停服务
                /// </summary>
                public int hasFee { get; set; }
                /// <summary>
                /// 服务项列表
                /// </summary>
                public List<int> svcList { get; set; }
            }
        }
        /// <summary>
        /// 费用信息
        /// </summary>
        public FeeInfo feeInfo { get; set; }

        /// <summary>
        /// 判断使用可使用某项服务项目（需获取用户费用信息）
        /// -1: 未获取费用信息； 0：成功；1：未订购相关服务项目；2：欠费；3：暂停服务       
        /// </summary> 
        /// <param name="FnSL_ID">服务项目ID 1：家校互动；8：考勤</param>
        /// <returns></returns>
        public int CanUseService(int FnSL_ID)
        {
            var flag = 0;
            if (this.feeInfo == null || this.feeInfo.pkgList == null || this.feeInfo.pkgList.Count == 0) flag = -1;
            else
            {
                if (FnSL_ID == 1)
                {
                    var a = this.feeInfo.pkgList.Where(x => x.svcList != null && x.svcList.Exists(v => v.jRange(1, 2, 3, 4, 5))).ToList();
                    if (a.Count == 0) flag = 1;
                    else if (a.Exists(x => x.hasFee == 2)) flag = 3;
                    else if (!a.Exists(x => x.hasFee == 1)) flag = 2;
                }
                else if (FnSL_ID == 8)
                {
                    var a = this.feeInfo.pkgList.Where(x => x.svcList != null && x.svcList.Exists(v => v.jRange(8, 9, 10, 11, 12))).ToList();
                    if (a.Count == 0) flag = 1;
                    else if (a.Exists(x => x.hasFee == 2)) flag = 3;
                    else if (!a.Exists(x => x.hasFee == 1)) flag = 2;
                }
                else
                {
                    var a = this.feeInfo.pkgList.Where(x => x.svcList != null && x.svcList.Exists(v => v == FnSL_ID)).ToList();
                    if (a.Count == 0) flag = 1;
                    else if (a.Exists(x => x.hasFee == 2)) flag = 3;
                    else if (!a.Exists(x => x.hasFee == 1)) flag = 2;
                }
            }
            return flag;
        }
        #endregion

        /// <summary>
        /// 是否查询到学校
        /// </summary>
        public bool IsSchoolOK
        {
            get
            {
                return this.FnBSI_ID > 0 && !string.IsNullOrWhiteSpace(FsBSI_DBName) && !string.IsNullOrWhiteSpace(FsBSI_ServerIP);
            }
        }
        /// <summary>
        /// 是否查询到用户
        /// </summary>
        public bool IsUserOK
        {
            get
            {
                return IsSchoolOK && this.FnUI_CurrentID > 0 && this.FnUI_Type != -1 && this.FnUI_BaseID > 0;
            }
        }

        /// <summary>
        /// 判断学校控制项
        /// <para>1：考勤统计（教师菜单）；2：考勤统计（学生和家长菜单）；3：教师一卡通充值；4：消费短信推送（定制用户）；5：同步考勤和消费信息到卓望平台；6：禁止用户充值功能费；7：禁止留言回复；8：禁止用户查询消费记录；9：签到推送；10：教师通讯录；11：教师考勤推送；12：禁止学生一卡通充值；13：一卡通在线挂失；14：班级考勤；15：禁止购买学平险；16：ACS通道与考勤组匹配；17：禁止查看老师考勤；</para>
        /// </summary>
        /// <param name="idx"></param>
        /// <returns></returns>
        public bool CheckControlSets(int idx)
        {
            if (!IsSchoolOK) return false;
            if (idx <= 0 || idx > 64) return false;
            return this.FsBSI_ControlSets.xTrim().PadRight(64, '0').Substring(idx - 1, 1) == "1";
        }
    }

    public partial class T_S_OperatorInfo
    {
        List<T_S_FunctionList> _FunctionList = new List<T_S_FunctionList>();
        /// <summary>
        /// 权限列表
        /// </summary>
        public List<T_S_FunctionList> FunctionList { get { return _FunctionList; } set { _FunctionList = value; } }

        int _FnDP_ID;
        /// <summary>
        /// 部门ID
        /// </summary>
        public int FnDP_ID
        {
            get { return _FnDP_ID; }
            set
            {
                if (_FnDP_ID != value)
                {
                    _FnDP_ID = value;
                    this.RaisePropertyChanged(v => v.FnDP_ID);
                }
            }
        }

        string _FsDP_Name;
        /// <summary>
        /// 部门名称
        /// </summary>
        public string FsDP_Name
        {
            get { return _FsDP_Name; }
            set { _FsDP_Name = value; this.RaisePropertyChanged(v => v.FsDP_Name); }
        }

        string _FxDP_FullName;
        /// <summary>
        /// 部门名称
        /// </summary>
        public string FxDP_FullName
        {
            get { return _FxDP_FullName; }
            set { _FxDP_FullName = value; this.RaisePropertyChanged(v => v.FxDP_FullName); }
        }

        /// <summary>
        /// 请求来源 0：默认； 1：服务号；3：企业号；4：网站；5：后台；6：公共；7：小程序；
        /// </summary>
        public int AppID { get; set; }

        string _BackgroundKey = "";
        /// <summary>
        /// 后台登录Key
        /// </summary>
        public string BackgroundKey { get { return _BackgroundKey; } set { _BackgroundKey = value; } }
    }

    /// <summary>
    /// 员工
    /// </summary>
    public partial class T_S_OperatorInfo : mCurrentUser
    {

        int _OldID = -1;
        public int OldID { get { return _OldID; } set { if (_OldID != value) { _OldID = value; this.RaisePropertyChanged(v => v.OldID); } } }

        int _FnOI_ID = -1;
        public int FnOI_ID { get { return _FnOI_ID; } set { if (_FnOI_ID != value) { _FnOI_ID = value; this.RaisePropertyChanged(v => v.FnOI_ID); } } }

        private string _FsOI_CID;
        [Attr("帐号", Required = true, isRegName = true)]
        public string FsOI_CID
        {
            get { return _FsOI_CID; }
            set
            {
                if (_FsOI_CID != value)
                {
                    _FsOI_CID = value;
                    this.RaisePropertyChanged(v => v.FsOI_CID);
                }
            }
        }
        private string _FsOI_Name;

        [Attr("姓名", maxLen = 32, Required = true)]
        public string FsOI_Name
        {
            get { return _FsOI_Name; }
            set
            {
                if (_FsOI_Name != value)
                {
                    _FsOI_Name = value;
                    this.RaisePropertyChanged(v => v.FsOI_Name);
                }
            }
        }
        private string _FsOI_Password;

        [Attr("密码", Required = true, isRegPwd = true)]
        public string FsOI_Password
        {
            get { return _FsOI_Password; }
            set
            {
                if (_FsOI_Password != value)
                {
                    _FsOI_Password = value;
                    this.RaisePropertyChanged(v => v.FsOI_Password);
                }
            }
        }
        private string _FsOI_WorkPhone;

        [Attr("工作电话", maxLen = 32, isMobie = true)]
        public string FsOI_WorkPhone
        {
            get { return _FsOI_WorkPhone; }
            set
            {
                if (_FsOI_WorkPhone != value)
                {
                    _FsOI_WorkPhone = value;
                    this.RaisePropertyChanged(v => v.FsOI_WorkPhone);
                }
            }
        }

        private string _FsOI_HomePhone;
        [Attr("联系电话", maxLen = 32, isPhone = true)]
        public string FsOI_HomePhone
        {
            get { return _FsOI_HomePhone; }
            set
            {
                if (_FsOI_HomePhone != value)
                {
                    _FsOI_HomePhone = value;
                    this.RaisePropertyChanged(v => v.FsOI_HomePhone);
                }
            }
        }

        private string _FsOI_Address;
        [Attr("地址", maxLen = 128)]
        public string FsOI_Address
        {
            get { return _FsOI_Address; }
            set
            {
                if (value != _FsOI_Address)
                {
                    _FsOI_Address = value;
                    this.RaisePropertyChanged(v => v.FsOI_Address);
                }
            }
        }

        private short _FnOI_IsOperator = 1;
        /// <summary>
        /// 0：管理员；1：内部员工；2：第三方维护；3：售卡点
        /// </summary>
        [Attr("员工标识", Required = true)]
        public short FnOI_IsOperator
        {
            get { return _FnOI_IsOperator; }
            set
            {
                if (value != _FnOI_IsOperator)
                {
                    _FnOI_IsOperator = value;
                    this.RaisePropertyChanged(v => v.FnOI_IsOperator);
                }
            }
        }

        private short _FnOI_Status;
        [Attr("工作状态", Required = true)]
        public short FnOI_Status
        {
            get { return _FnOI_Status; }
            set
            {
                if (value != _FnOI_Status)
                {
                    _FnOI_Status = value;
                    this.RaisePropertyChanged(v => v.FnOI_Status);
                }
            }
        }

        private int _FfnOI_ModifyID;
        public int FfnOI_ModifyID
        {
            get { return _FfnOI_ModifyID; }
            set
            {
                if (value != _FfnOI_ModifyID)
                {
                    _FfnOI_ModifyID = value;
                    this.RaisePropertyChanged(v => v.FfnOI_ModifyID);
                }
            }
        }
        private DateTime _FdOI_MakeTime;

        public DateTime FdOI_MakeTime
        {
            get { return _FdOI_MakeTime; }
            set
            {
                if (value != _FdOI_MakeTime)
                {
                    _FdOI_MakeTime = value;
                    this.RaisePropertyChanged(v => v.FdOI_MakeTime);
                }
            }
        }
    }
}
